/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package bpmn.impl;

import bpmn.BpmnPackage;
import bpmn.Lane;
import bpmn.Participant;
import bpmn.Pool;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Pool</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link bpmn.impl.PoolImpl#getProcessRef <em>Process Ref</em>}</li>
 *   <li>{@link bpmn.impl.PoolImpl#getParticipantRef <em>Participant Ref</em>}</li>
 *   <li>{@link bpmn.impl.PoolImpl#getLanes <em>Lanes</em>}</li>
 *   <li>{@link bpmn.impl.PoolImpl#getBoundaryVisible <em>Boundary Visible</em>}</li>
 *   <li>{@link bpmn.impl.PoolImpl#getMainPool <em>Main Pool</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class PoolImpl extends SwimlaneImpl implements Pool {
	/**
	 * The cached value of the '{@link #getProcessRef() <em>Process Ref</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProcessRef()
	 * @generated
	 * @ordered
	 */
	protected bpmn.Process processRef;

	/**
	 * The cached value of the '{@link #getParticipantRef() <em>Participant Ref</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParticipantRef()
	 * @generated
	 * @ordered
	 */
	protected Participant participantRef;

	/**
	 * The cached value of the '{@link #getLanes() <em>Lanes</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLanes()
	 * @generated
	 * @ordered
	 */
	protected EList<Lane> lanes;

	/**
	 * The default value of the '{@link #getBoundaryVisible() <em>Boundary Visible</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBoundaryVisible()
	 * @generated
	 * @ordered
	 */
	protected static final Boolean BOUNDARY_VISIBLE_EDEFAULT = Boolean.TRUE;

	/**
	 * The cached value of the '{@link #getBoundaryVisible() <em>Boundary Visible</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBoundaryVisible()
	 * @generated
	 * @ordered
	 */
	protected Boolean boundaryVisible = BOUNDARY_VISIBLE_EDEFAULT;

	/**
	 * The default value of the '{@link #getMainPool() <em>Main Pool</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMainPool()
	 * @generated
	 * @ordered
	 */
	protected static final Boolean MAIN_POOL_EDEFAULT = Boolean.FALSE;

	/**
	 * The cached value of the '{@link #getMainPool() <em>Main Pool</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMainPool()
	 * @generated
	 * @ordered
	 */
	protected Boolean mainPool = MAIN_POOL_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected PoolImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BpmnPackage.Literals.POOL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public bpmn.Process getProcessRef() {
		return processRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetProcessRef(bpmn.Process newProcessRef, NotificationChain msgs) {
		bpmn.Process oldProcessRef = processRef;
		processRef = newProcessRef;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, BpmnPackage.POOL__PROCESS_REF, oldProcessRef, newProcessRef);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProcessRef(bpmn.Process newProcessRef) {
		if (newProcessRef != processRef) {
			NotificationChain msgs = null;
			if (processRef != null)
				msgs = ((InternalEObject)processRef).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - BpmnPackage.POOL__PROCESS_REF, null, msgs);
			if (newProcessRef != null)
				msgs = ((InternalEObject)newProcessRef).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - BpmnPackage.POOL__PROCESS_REF, null, msgs);
			msgs = basicSetProcessRef(newProcessRef, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.POOL__PROCESS_REF, newProcessRef, newProcessRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Participant getParticipantRef() {
		if (participantRef != null && participantRef.eIsProxy()) {
			InternalEObject oldParticipantRef = (InternalEObject)participantRef;
			participantRef = (Participant)eResolveProxy(oldParticipantRef);
			if (participantRef != oldParticipantRef) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.POOL__PARTICIPANT_REF, oldParticipantRef, participantRef));
			}
		}
		return participantRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Participant basicGetParticipantRef() {
		return participantRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParticipantRef(Participant newParticipantRef) {
		Participant oldParticipantRef = participantRef;
		participantRef = newParticipantRef;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.POOL__PARTICIPANT_REF, oldParticipantRef, participantRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Lane> getLanes() {
		if (lanes == null) {
			lanes = new EObjectContainmentEList<Lane>(Lane.class, this, BpmnPackage.POOL__LANES);
		}
		return lanes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Boolean getBoundaryVisible() {
		return boundaryVisible;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBoundaryVisible(Boolean newBoundaryVisible) {
		Boolean oldBoundaryVisible = boundaryVisible;
		boundaryVisible = newBoundaryVisible;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.POOL__BOUNDARY_VISIBLE, oldBoundaryVisible, boundaryVisible));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Boolean getMainPool() {
		return mainPool;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMainPool(Boolean newMainPool) {
		Boolean oldMainPool = mainPool;
		mainPool = newMainPool;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.POOL__MAIN_POOL, oldMainPool, mainPool));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case BpmnPackage.POOL__PROCESS_REF:
				return basicSetProcessRef(null, msgs);
			case BpmnPackage.POOL__LANES:
				return ((InternalEList<?>)getLanes()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case BpmnPackage.POOL__PROCESS_REF:
				return getProcessRef();
			case BpmnPackage.POOL__PARTICIPANT_REF:
				if (resolve) return getParticipantRef();
				return basicGetParticipantRef();
			case BpmnPackage.POOL__LANES:
				return getLanes();
			case BpmnPackage.POOL__BOUNDARY_VISIBLE:
				return getBoundaryVisible();
			case BpmnPackage.POOL__MAIN_POOL:
				return getMainPool();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case BpmnPackage.POOL__PROCESS_REF:
				setProcessRef((bpmn.Process)newValue);
				return;
			case BpmnPackage.POOL__PARTICIPANT_REF:
				setParticipantRef((Participant)newValue);
				return;
			case BpmnPackage.POOL__LANES:
				getLanes().clear();
				getLanes().addAll((Collection<? extends Lane>)newValue);
				return;
			case BpmnPackage.POOL__BOUNDARY_VISIBLE:
				setBoundaryVisible((Boolean)newValue);
				return;
			case BpmnPackage.POOL__MAIN_POOL:
				setMainPool((Boolean)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case BpmnPackage.POOL__PROCESS_REF:
				setProcessRef((bpmn.Process)null);
				return;
			case BpmnPackage.POOL__PARTICIPANT_REF:
				setParticipantRef((Participant)null);
				return;
			case BpmnPackage.POOL__LANES:
				getLanes().clear();
				return;
			case BpmnPackage.POOL__BOUNDARY_VISIBLE:
				setBoundaryVisible(BOUNDARY_VISIBLE_EDEFAULT);
				return;
			case BpmnPackage.POOL__MAIN_POOL:
				setMainPool(MAIN_POOL_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case BpmnPackage.POOL__PROCESS_REF:
				return processRef != null;
			case BpmnPackage.POOL__PARTICIPANT_REF:
				return participantRef != null;
			case BpmnPackage.POOL__LANES:
				return lanes != null && !lanes.isEmpty();
			case BpmnPackage.POOL__BOUNDARY_VISIBLE:
				return BOUNDARY_VISIBLE_EDEFAULT == null ? boundaryVisible != null : !BOUNDARY_VISIBLE_EDEFAULT.equals(boundaryVisible);
			case BpmnPackage.POOL__MAIN_POOL:
				return MAIN_POOL_EDEFAULT == null ? mainPool != null : !MAIN_POOL_EDEFAULT.equals(mainPool);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (BoundaryVisible: ");
		result.append(boundaryVisible);
		result.append(", MainPool: ");
		result.append(mainPool);
		result.append(')');
		return result.toString();
	}

} //PoolImpl
